#!/bin/bash
#export donation_record data into daily csv file
#echo "start export data from table donation"
#DATE2=`date +%Y%m%d-%H%M`
DATE=`date +%Y%m%d`
DBNAME=acms
USERNAME=root
PASSWORD=acms*123
select_sql="select * into outfile '/usr/tomcat/db_data_backup/donation-${DATE}.csv' fields terminated by ',' optionally enclosed by '\"' lines terminated by '\n' from donation_record;"
mysql -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${select_sql}"
#echo "export completed,start to upload csv file to ftps server..."
sleep 3
#upload csv file to imt ftp server
#DATE1=`date +%Y%m%d-%H%M`

lftp << EOF 
open WCE:WCE_R3x1@ftps.imtnetwork.com
cd MySQL
put /usr/tomcat/db_data_backup/donation-${DATE}.csv
bye
EOF
#echo "upload file to ftps server complete"
exit 0
